package com.binvshe.binvshe.mine;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.binvshe.binvshe.R;
import com.f2prateek.dart.Dart;
import com.f2prateek.dart.InjectExtra;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.utils.EasyToast;

import butterknife.Bind;

public class SignActivity extends BaseActivity {

    @Bind(R.id.mEtSign)
    EditText mEtSign;

    private static final String KEY_SIGN = "key_sign";
    public static final String RESULT_STRING = "result_string";

    private String mSign;

    public static void start(Activity activity, String sign, int resultCode) {
        Intent starter = new Intent(activity, SignActivity.class);
        starter.putExtra(KEY_SIGN, sign);
        activity.startActivityForResult(starter, resultCode);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mSign = getIntent().getStringExtra(KEY_SIGN);
        mEtSign.setText(mSign);
        initToolBar();
    }

    private void initToolBar() {
        enableBackButton();
        getCustomToolbar().setTitle("签名");
        getCustomToolbar().addRightButton("保存", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String sign = mEtSign.getText().toString().trim();
                if (TextUtils.isEmpty(sign)) {
                    EasyToast.showToast(SignActivity.this, "签名不能为空");
                    return;
                }
                if (sign.length() > 120) {
                    EasyToast.showToast(SignActivity.this, "限定字数120个");
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra(RESULT_STRING, sign);
                setResult(RESULT_OK, intent);
                SignActivity.this.finish();
            }
        });
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.act_sign, null);
    }
}
